package com.fs.sys.entityservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fs.sys.bean.dto.UserAppDTO;
import com.fs.sys.bean.query.UserAppQuery;
import com.fs.sys.domain.entity.UserAppEntity;
import com.fs.sys.domain.mapper.UserAppMapper;
import com.fs.sys.entityservice.AppEntityService;
import com.fs.sys.entityservice.UserAppEntityService;
import com.fs.common.base.service.AbstractSimpleEntityService;
import com.fs.sys.service.TenantAppService;
import com.fs.sys.entityservice.TenantEntityService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户应用关系服务实现 
 * @author Coder Generator 2025-06-06 11:03:15 
 **/
@Service
public class UserAppEntityServiceImpl extends AbstractSimpleEntityService<UserAppEntity, UserAppDTO, UserAppMapper, UserAppQuery> implements UserAppEntityService {
    @Autowired
    private TenantEntityService tenantEntityService;

    @Autowired
    private TenantAppService tenantAppService;

    @Autowired
    private AppEntityService appEntityService;

    @Override
    protected QueryWrapper<UserAppEntity> queryToWrapper(UserAppQuery query) {
        return this.createQueryWrapper()
                .eq(StringUtils.isNotBlank(query.getId()), "id", query.getId())
                .eq(StringUtils.isNotBlank(query.getAppId()), "app_id", query.getAppId())
                .in(null != query.getIds(), "id", query.getIds());
    }

    /**
     * 查找用户有权限的应用id列表
     *
     * @param userId 用户id
     * @return 应用id列表
     */
    @Override
    public List<String> findUserDispatchedAppIds(String userId) {
        return baseMapper.findUserDispatchedAppIds(userId);
    }
}